home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / powerb5.zip / P5DOS008.TIP < prev    next >
Text File  |  1993-06-01  |  5KB  |  109 lines

  1. Many programs, including word processors and spreadsheets,
  2. allow you to temporarily shell out to DOS. But if you are in
  3. one of these temporary DOS sessions when you invoke a batch
  4. file -- especially one of the more complex ones featured in
  5. Star-Dot-Star --you may find that the batch fails for lack
  6. of environment space.
  7.  
  8. Here's why. When you shell out of a typical application
  9. program, DOS re-creates a new environment space, with copies
  10. of all the existing environment variables, in whatever
  11. unused memory it finds. But since it anticipates a potential
  12. memory shortage, DOS makes the new environment space just
  13. big enough to hold all the existing variables; it doesn't
  14. leave any room for new ones! Thus, when a batch file
  15. attempts to create a new environment variable, it gets an
  16. 'Out of environment space' error message. The batch
  17. continues, but produces incorrect (or even dangerous)
  18. results because it can't save information in the
  19. environment. One solution to this problem is to create a
  20. "dummy" environment variable for reserving space. For
  21. instance, if you add the line SET RESERVE=XX.....XXX (where
  22. there are 120 X's on the line) to your AUTOEXEC.BAT file,
  23. another batch file can reclaim the room in its own
  24. environment with the command SET RESERVE= (where nothing
  25. follows the equal sign). The problem with this approach is
  26. that everyone who might use the batch file must have the
  27. command in his or her AUTOEXEC.BAT if the other batch files
  28. are to access the extra room.
  29.  
  30. Here's another solution: If you know a batch file will
  31. require lots of environment space, but you don't know how
  32. much will be available, you can design the batch file to
  33. temporarily enlarge its own environment. BIGENV.BAT provides
  34. an example of how you can do this.
  35.  
  36. BIGENV.BAT works by calling itself. When launched,
  37. BIGENV.BAT checks if its first parameter contains ?Do_It?.
  38. If not, BIGENV runs COMMAND.COM with two switches: /E:1024,
  39. to create a 1K environment, and /C, to run the string that
  40. follows as a command. That string runs the batch file again,
  41. this time passing it the ?Do_It? parameter. Because of the
  42. passed parameter, BIGENV skips to the Do_It label when it
  43. runs inside of itself. A SHIFT command deletes the special
  44. argument and shifts the others to the left. The batch can
  45. now continue, knowing that it has enough room to work. When
  46. the batch is finished, the recursion "unwinds" and the extra
  47. COMMAND.COM, with its 1K environment space, is unloaded.
  48.  
  49. Ron Lewis
  50. Huntsville, Alabama
  51.  
  52. Editor's Note: Each of these approaches is useful under
  53. different circumstances. The "reserve" variable is ideal
  54. when you need a small amount of space (the most you can
  55. reclaim is 123 bytes), and you can edit AUTOEXEC.BAT and
  56. your other batch files to use it. Unlike the second
  57. technique, this one guarantees that you'll get a specific
  58. amount of free environment space, and it doesn't take up
  59. extra RAM by reinvoking COMMAND.COM. The downside of this
  60. technique: if your batch file CALLs another that also uses
  61. the same "reserve" variable, the two will compete for the
  62. same RAM and one of them won't work.
  63.  
  64. The second technique is better when you need more room. It's
  65. also easier to set up, because all you need to do is place
  66. the appropriate commands at the beginning and end of an
  67. existing batch file with heavy environmental needs. However,
  68. this method has two drawbacks. First, because it tries to
  69. load another copy of the transient portion of COMMAND.COM
  70. (which can be as big as 17K), it wastes conventional RAM.
  71. Second, the amount of free environment space provided by
  72. this technique isn't guaranteed. If your system already has
  73. 1009 bytes of environment variables, /E:1024 will provide no
  74. more space than you had before. (DOS always rounds the size
  75. of the environment up to a multiple of 16 bytes.) For this
  76. reason, I recommend this technique primarily for situations
  77. in which you can closely estimate the amount of environment
  78. space that's already been used.
  79.  
  80. As you may have noticed, this volume of PowerBase *.* has
  81. several tips with batch files that call themselves; each of
  82. these files uses a similar technique to solve a very
  83. different problem. Just goes to show what a little bit of
  84. creativity can do.
  85.  
  86. BIGENV.BAT
  87.  
  88. ---- BEGIN LISTING ----
  89. @ECHO OFF
  90. IF "%1" == "?Do_It?" GOTO Do_It
  91. COMMAND.COM /E:1024 /C BIGENV ?Do_It? %1 %2 %3 %4 %5 %6 %7
  92. %8 %9
  93. GOTO Exit
  94.  
  95. :Do_It
  96. SHIFT
  97. REM  Place call to regular batch file command on next line
  98.  
  99. :Exit
  100. ---- END LISTING ----
  101.  
  102.  
  103. Title: Ways to Save the Environment
  104. Category: DOS
  105. Issue Date: August, 1992
  106. Editor: Brett Glass
  107. Supplementary Files: None
  108. Filename: P5DOS008.TIP
  109.